package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.client.ClazzClient;
import cn.kgc.springcloud.commons.ResponseResult;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.vo.GroupVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.mapper.GroupMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_group】的数据库操作Service实现
* @createDate 2024-05-09 08:45:08
*/
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group>implements GroupService{

    @Resource
    private ClazzClient clazzClient;

    @Override
    public ResponseResult groupList() {

        List<Group> groups = baseMapper.selectList(null);
        List<GroupVO> collect = groups.stream().map(group -> {
            GroupVO groupVO = new GroupVO();
            BeanUtils.copyProperties(group,groupVO);

            Integer clazzid = Integer.valueOf(group.getClazzid());
            // 通过client调用 班级服务
            Clazz clazz = clazzClient.getOneClazz(clazzid);
            groupVO.setClazz(clazz);
            return groupVO;
        }).collect(Collectors.toList());

        return ResponseResult.success().data(collect);
    }
}




